<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
            <el-breadcrumb-item :to="{ path: '/sys-admin' }">
                <i class="el-icon-s-promotion"></i> 后台管理
            </el-breadcrumb-item>
            <el-breadcrumb-item>属性模板列表</el-breadcrumb-item>
        </el-breadcrumb>

        <el-table :data="tableData" stripe style="width: 100%" border>
            <el-table-column prop="id" label="序号" align="center" width="180"></el-table-column>
            <el-table-column prop="name" label="姓名" align="center" width="230"></el-table-column>
            <el-table-column prop="pinyin" header-align="center" label="拼音"></el-table-column>
            <el-table-column prop="keywords" header-align="center" label="关键字"></el-table-column>
            <el-table-column prop="sort" align="center" label="排序" width="100"></el-table-column>
            <el-table-column align="center" label="操作" width="100">
                <template slot-scope="scope">
                    <el-button type="primary" icon="el-icon-edit" size="mini" circle @click="handleEdit(scope.row)"></el-button>
                    <el-button type="danger" icon="el-icon-delete" size="mini" circle @click="handleDelete(scope.row)"></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

</template>

<script>
    export default {
        data() {
            return {
                tableData: [{
                    id: '2016-05-02',
                    name: '王小虎',
                    pinyin: '上海市普陀区金沙江路 1518 弄',
                    keywords:'',
                    sort:''
                }]
            }
        },
        methods:{
            loadAttrTempList(){
                let url = "http://localhost:9080/attr/template/list";
                console.log('loadAlbumList()');
                this.axios
                    .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
                    .get(url).then((response) =>{
                    this.tableData = response.data.data;
                })
            },
            handleDelete(attrTemp){
                this.$confirm('此操作将永久删除'+attrTemp.name+', 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let url = "http://localhost:9080/attr/template/deleteById?id="+attrTemp.id;
                    this.axios
                        .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
                        .get(url).then((response) =>{
                            let responseBody = response.data;
                            if(responseBody.state!=20000){
                                this.$message.error(responseBody.message);
                            }
                            this.loadAttrTempList();
                    })
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            handleEdit(attrTemp){
                let url = "http://localhost:9080/attr/template/edit";
            }
        },
        created(){
            console.log('created()');
        },
        mounted(){
            console.log('mounted()');
            this.loadAttrTempList();
        }
    }
</script>

<style scoped>

</style>